﻿using System;
using System.Collections.Generic;
using System.Text;
using CadStrategy2013.DxfData;
using MyIni;

namespace ReadDataDsDl_Ini
{
    public class ReadDataClass:ReadDataInterface
    {
        public DxfDataClass GetDxfData(string StationName,int BanCount)
        {
            DxfDataClass dxfDataClass = new DxfDataClass();

            IniFile inifile = new IniFile("./\\" + StationName + "\\xhj.txt");
            GetFx_Fx31(dxfDataClass, inifile);
            GetFx02(dxfDataClass, inifile);
            GetOther(dxfDataClass, inifile);
            GetUm71(dxfDataClass, inifile);
            dxfDataClass.ShiJiBanCount = dxfDataClass.devList.Count;/// BanDevCount + 1;
            dxfDataClass.ShiJiTuZhiCount = dxfDataClass.ShiJiBanCount / BanCount + 1;
            return dxfDataClass;
        }
        private void GetFx_Fx31(DxfDataClass dxfDataClass, IniFile inifile)
        {
            string[] strSecs = new string[] { "信号机JX", "信号机3FX31" };
            foreach (string strSec in strSecs)
            {
                int sum0 = inifile.GetInt16(strSec, "sum", 0);
                string str1s = inifile.GetString(strSec, "定型配线", "");
                string[] strDingXings = str1s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < sum0; i++)
                {
                    DevClass devClass = new DevClass();
                    string strs = inifile.GetString(strSec, (i + 1).ToString(), "");
                    string[] otherData = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    devClass.DevName = otherData[0];
                    for (int j = 0; j < 4; j++)
                    {
                        devClass.peiList.Add(otherData[1] + strDingXings[j]);
                    }
                    dxfDataClass.devList.Add(devClass);
                }
            }
        }
        private void GetFx02(DxfDataClass dxfDataClass, IniFile inifile)
        {
            int sum0 = inifile.GetInt16("信号机3FX02", "sum", 0);
            string str1s = inifile.GetString("信号机3FX02", "定型配线A", "");
            string[] strDingXingsA = str1s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string str2s = inifile.GetString("信号机3FX02", "定型配线B", "");
            string[] strDingXingsB = str2s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("信号机3FX02", (i + 1).ToString(), "");
                string[] otherData = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (otherData[2] == "A")
                {
                    devClass.DevName = otherData[0];
                    for (int j = 0; j < 4; j++)
                    {
                        devClass.peiList.Add(otherData[1] + strDingXingsA[j]);
                    }
                }
                if (otherData[2] == "B")
                {
                    devClass.DevName = otherData[0];
                    for (int j = 0; j < 4; j++)
                    {
                        devClass.peiList.Add(otherData[1] + strDingXingsB[j]);
                    }
                }
                dxfDataClass.devList.Add(devClass);
            }
        }
        private void GetOther(DxfDataClass dxfDataClass, IniFile inifile)
        {
            int sum0 = inifile.GetInt16("其他信号机", "sum", 0);
            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("其他信号机", (i + 1).ToString(), "");
                string[] otherData = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                devClass.DevName = otherData[0];
                if (otherData.Length == 1)
                {
                    for (int j = 1; j < 5; j++)
                    {
                        devClass.peiList.Add("");
                    }
                }
                else
                {
                    for (int j = 1; j < otherData.Length; j++)
                    {
                        devClass.peiList.Add(otherData[0] + otherData[j]);
                    }
                }
                dxfDataClass.devList.Add(devClass);
            }
        }
        private void GetUm71(DxfDataClass dxfDataClass, IniFile inifile)
        {
            string[] strName = new string[] { "-L电流", "-H电流", "-U电流" };
            int sum0 = inifile.GetInt16("区间信号机UM71", "sum", 0);
            string str1s = inifile.GetString("区间信号机UM71", "定型配线", "");
            string[] strDingXings = str1s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < sum0; i++)
            {
                DevClass devClass = new DevClass();
                string strs = inifile.GetString("区间信号机UM71", (i + 1).ToString(), "");
                string[] otherData = strs.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                devClass.DevName = otherData[0];
                for (int j = 0; j < 2; j++)
                {
                    devClass.peiList.Add(otherData[1] + strDingXings[j]);
                    devClass.peiList.Add(otherData[j + 2]);
                }
                dxfDataClass.devList.Add(devClass);

                DevClass devClass1 = new DevClass();
                devClass1.DevName = otherData[0];
                devClass1.peiList.Add(otherData[1] + strDingXings[2]);
                devClass1.peiList.Add(otherData[4]);
                devClass1.peiList.Add("- ");
                devClass1.peiList.Add("- ");
                dxfDataClass.devList.Add(devClass1);
            }
        }
    }
}
